home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / comm / yrndl140.zip / yarndial.cmd < prev    next >
OS/2 REXX Batch file  |  1996-09-25  |  65KB  |  2,019 lines

  1. /* YARNDIAL.CMD v 1.40 by Jerry Levy     24 Sep 1996
  2. Comments appreciated: send to jlevy@ibm.net
  3. (Jerry Levy, Marblehead, MA USA) */
  4.  
  5. version = '1.40'
  6. /* Fix 1 has been applied */
  7. /*
  8.  
  9. =======ERROR TRAPPING   =========
  10. We can trap and identify various types of ReXX error
  11. conditions:  Error, Syntax, Failure, Novalue, Halt
  12. and Notready, by setting 
  13.     local_error_trapping = 1
  14.  
  15. Default is
  16.     local_error_trapping = 0
  17. but if you have problems, briefly setting this equal
  18. to 1 may help you identify source of an error.
  19. ==================================
  20.  
  21. */
  22. local_error_trapping = 0
  23. /*
  24. ===========History============
  25. See YD.DOC for details.
  26. YARNDIAL.CMD 1.40          24 Sep 96
  27.  
  28.     and companion installer:
  29. YDINSTL.CMD  v 1.40         24 Sep 96
  30.  
  31.  
  32. ==========COPYRIGHT NOTICE AND DISCLAIMER=============
  33. YDINSTL.CMD is Copyright 1996 by Jerry Levy (all rights reserved)
  34. YARNDIAL.CMD is Copyright 1995 and 1996 by Jerry Levy (all rights reserved)
  35.  
  36. These are provided as-is and without charge, with no warranty expressed
  37. or implied as to merchantability or fitness for any particular purpose.  All
  38. responsibility for any and all incidental and consequential damages is
  39. disclaimed.  These programs and associated text files are freeware.  They
  40. may be distributed without restriction providing: (1) this notice and
  41. disclaimer remain intact, (2) all programs and files are included and
  42. unchanged, and (3) they are distributed either in the original .zip archive
  43. or the archive after being unzipped into a folder or onto a disk or other
  44. medium.  Use of either or both of these programs constitutes acceptance
  45. of these terms by all users.
  46.  
  47. ================INSTALLATION======================
  48. You could read YD.DOC.
  49. Or you could read README.1ST (shorter, recommended).
  50.  
  51. If YARN and SOUPER are installed and run OK...
  52.  
  53. ...and if you are using the IAK Dialer to connect to Advantis,
  54. or the Dial-Other-Internet_Providers utility (SLIPPM.EXE)...
  55.  
  56. then just run YDINSTL.CMD.
  57. ==================================================
  58.  
  59. */
  60.  
  61. arg otherparms        /* for later contingency */
  62.  
  63. cr = d2c(13)        /* enter key, as well as carriage return */
  64. crlf = d2c(13) || d2c(10)    /* carriage return + linefeed */
  65. escape = d2c(27)    /* escape character */
  66. ctrl_Q = d2c(17)
  67. ctrl_R = d2c(18)
  68. bs = d2c(8)    /* Backspace */
  69. tab = d2c(9)    /* tab */
  70. X1 = d2c(0)    /* Extended key */
  71. X2 = d2c(224)    /* Extended key */
  72.  
  73. say ''
  74. say 'YRNDIAL.CMD v' || version
  75. say '(c) 1995 & 1996 by Jerry Levy (all rights reserved)'
  76. say 'jlevy@ibm.net    Marblehead, MA USA'
  77. say ''
  78. say 'Dials in, gets or posts news, mail and replies.'
  79. say 'Normal operation is to sign off when done.' crlf
  80. time1 = time()
  81. date1 = date('S')
  82. date1 = left(date1,4) || '/' || substr(date1,5,2) || '/' || right(date1,2)
  83. /* format date as yyyy/mm/dd */
  84.  
  85. /* This program has been tested with various recent YARN and
  86. SOUPER versions through YRN2_091 and SOUPER15 */
  87.  
  88. if local_error_trapping then signal on failure
  89. if local_error_trapping then signal on halt
  90. if local_error_trapping then signal on syntax
  91. if local_error_trapping then signal on notready
  92. if local_error_trapping then signal on error
  93. if local_error_trapping then signal on novalue
  94.  
  95. trace 'N'
  96.  
  97. timeout = 0
  98. /* Flag is reset to 1 if dialer times out */
  99.  
  100. Abandon = 0     /* Initialize*/
  101. replies_zip = 1    /* if we try to export mail and there is none, this is reset to 0 */
  102. do_catchup_on_news = 0    /* initialize the flag to no news catchup */
  103.  
  104. /* MAIN PROGRAM */
  105.  
  106. /* Load Rexx Util functions if not already loaded */
  107. if RxFuncQuery('SysLoadFuncs') \= 0 then
  108.    do
  109.       call RxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
  110.       call SysLoadFuncs
  111.    end
  112.  
  113. /* Initialize these filenames */
  114. go_exe = 'GO.EXE'
  115. ydinstl_cmd = 'YDINSTL.CMD'
  116. ydparms_dat = 'YD_PARMS.DAT'
  117. killjoy_exe = 'KILLJOY.EXE'
  118. alt_dialer_exe = 'SLIPPM.EXE'
  119.  
  120. '@echo off'                /* No echoing of any os/2 commands */
  121. home = directory()            /* Where we are executing this pgm from */
  122. home = translate(home)
  123.  
  124. ydparms_dat = home || '\' || ydparms_dat /* All the parameters we need are here */
  125. /* Abort if can't locate the ydparms_dat.  Means we never ran the installer */
  126. if stream(ydparms_dat, 'c', 'query exists') = '' then
  127.    do
  128.       go_exe = home || '\' || go_exe    /* assume that's where it is */
  129.       call beep 1000, 200
  130.       say 'Cannot find YD_PARMS.DAT, the file containing parameters'
  131.       say 'YARNDIAL needs in order to run.  This is normal if you have'
  132.       say 'not yet run the installer,' ydinstl_cmd || '.'
  133.       say ''
  134.       say 'Aborting.  Press any key to exit.  Then run' ydinstl_cmd
  135.       call SysGetKey 'NOECHO'
  136.       signal goodbye
  137.    end
  138.  
  139. say 'Please wait while parameters load and we perform our setup...'
  140.  
  141.  
  142. do_not_kill = 0
  143.  
  144. /* Read parameters in from the ydparms.dat datafile */
  145. call parms_from_ydparms_dat
  146. /*
  147. ============
  148. DO NOT KILL OPTION
  149. If the DO_NOT_KILL_CONNECTION parameter in YD_PARMS.DAT =1
  150. we can have the option come up in the main menu to kill or not
  151. to kill the connection when YARNDIAL finishes.  If it is zero,
  152. we always kill the connection at the end.
  153.  
  154. dnk.1 thru .7 are the "do-not-kill" alternatives to
  155. 1-7 and on the main menu.  If do_not_kill is enabled (=1)
  156. you can execute the same functions as 1-7 but dialers, slip,
  157. etc. are not shut down when done.
  158.  
  159. For non-US keyboards, you should edit DNK_STRING in YD_PARMS.DAT
  160. for appropriate, convenient alternative keyboard chars to the
  161. US-keyboard default of !@#$%^& (shift-1 thru shift-7).
  162.  
  163. We parse the dnk_string to the 7 individual dnk.i alternate chars.
  164. ============
  165. */
  166. if pos(do_not_kill_connection, '01') = 0 then do_not_kill_connection = 0
  167.  
  168. dnk_string = '!@#$%^&'    /* shift-1 thru shift-7 on a US keyboard */
  169.  
  170. do i = 1 to 7
  171.    if substr(dnk_string, i, 1) \= '' & substr(dnk_string, i, 1) \= ' ' then
  172.       dnk.i = substr(dnk_string, i, 1)
  173.    else dnk.i = i
  174. end
  175.  
  176. /*
  177. ==================
  178. Get alt_dialer_exe filename.  Strip path, "." and extension,
  179. and also strip any options that may have been entered.
  180. alt_dialer_exe stores the name of the dialer executable. 
  181. ==================
  182. */
  183. parse var alt_dialer_exe alt_dialer_name alt_dialer_options    /* strip options */
  184. alt_dialer_name = translate(alt_dialer_name)           /* upper case */
  185. alt_dialer_name = filespec('name', alt_dialer_name)        /* eliminate drive and path */
  186. parse var alt_dialer_name alt_dialer '.' ext            /*...and extension */
  187.  
  188.  
  189. /*
  190. ====================
  191. (Re)set HOME and YARN environmental variables.
  192. Later, in the dialup_server() routine, we will (re)set
  193. the NNTPSERVER (newsserver, =default_news) environmental variable.
  194. In dialup_server() routine we decide the correct
  195. newsserver assignment, then we set NNTPSERVER to that.
  196. ====================
  197. */
  198.  
  199. x = SetLocal()
  200. x = value('home', home, 'OS2ENVIRONMENT')
  201. x = value('yarn', yarn, 'OS2ENVIRONMENT')
  202.  
  203. /* We look for some obvious inconsistencies or omissions in YDPARMS_DAT */
  204. call fatal_error_check
  205.  
  206. call directory_maintenance
  207.  
  208. /* are we connected? to whom? is it the right connection? */
  209. call get_current_connection
  210.  
  211. /*
  212. =============================================
  213. This is the main menu.  If we select 7 (souper options)
  214. we first dial in to the system and only after we're connected
  215. do we get to select the options.  Then we get another menu
  216. asking if we want to get or send stuff.
  217. =============================================
  218. */
  219.    say ''
  220.    say 'MAIN SELECTION MENU'
  221.    say '1  Only import Mail'
  222.    say '2  Only import News Articles'
  223.    say '3  Only import, but both Mail AND News'
  224.    say '4  Only export (send Mail, Posts, Replies, and Follow-ups)'
  225.    say '5  Everything: Get mail and news AND send Posts, Replies, and Follow-ups'
  226.    say '6  Complete an interrupted importation of mail/news'
  227.    say '         or rebuild a corrupted YARN history file'
  228.    say '7  Souper options:  one-time-only changes in how souper runs:'
  229.    say '      Catchup on News'
  230.    say '      Maximum News Packet Size'
  231.    say '      Do not retrieve newsgroup articles longer than set number of lines'
  232.    say '      Read-only for Mail: Don''t empty POP3 mailbox'
  233.    say 'Press:'
  234.    say '    1 2 3 4 5 6 7   Executes functions as shown; goes off-line when done'
  235.    if do_not_kill_connection then    /* ...then we have a choice */
  236.       do
  237.          say ' or' dnk.1 dnk.2 dnk.3 dnk.4 dnk.5 dnk.6 dnk.7,
  238.           '  Same functions; connection remains up'   
  239.       end
  240.  
  241.    say 'To exit now and close connection: Escape key'
  242.    if do_not_kill_connection then
  243.       say 'To exit, but leave any existing connection up: CTRL-Q'
  244.    say 'Enter Selection:'
  245.  
  246. do until pos(choice, '1234567' || Escape) \= 0 
  247.    choice = SysGetKey('NOECHO')
  248.  
  249. /*
  250. ==================
  251. We can select dnk.1 thru 7 whereby we elect to do the same things
  252. as for choices 1 thru 7 except we do not close down dialer
  253. and other connection stuff at the end.  If any of the dnk. characters
  254. are the 1,2,3,4,5,6, or 7, the numeric choice takes 
  255.  
  256. dnk.1 thru 7 default to the shift-key characters
  257. [on a US keyboard !@#$%^&] for keypresses 12345677]
  258. ==================
  259. */
  260.  
  261.    select
  262.       when choice = Escape then
  263.          do
  264.             say 'Quitting Yarndial...'
  265.             signal goodbye
  266.          end
  267.       when choice = ctrl_Q & \do_not_kill_connection then
  268.          do
  269.             choice = ''    /* Blank.  Something that is not a correct one */
  270.             say 'Selection must be 1-7 or Escape key.  Try again...'
  271.          end
  272.        when choice = ctrl_Q & do_not_kill_connection then
  273.          do
  274.             say 'Quitting Yarndial...'
  275.             do_not_kill = 1 
  276.             signal goodbye
  277.          end
  278.       when pos(choice, '1234567') = 0 & \do_not_kill_connection then
  279.          do
  280.             say ''
  281.             say 'Selection must be 1-7 or Escape key.  Try again...'
  282.             say ''
  283.         end
  284.       when pos(choice, '1234567') = 0,
  285.          & do_not_kill_connection,
  286.          & pos(choice, dnk_string) = 0 then
  287.          do
  288.             say ''
  289.             say 'Not an allowable selection, try again...'
  290.             say ''
  291.         end
  292.       when pos(choice, '1234567') = 0,
  293.           & pos(choice, dnk_string) \=0  then
  294.          do
  295.             do_not_kill = 1 
  296.             if choice = dnk.1 then choice = 1
  297.             if choice = dnk.2 then choice = 2
  298.             if choice = dnk.3 then choice = 3
  299.             if choice = dnk.4 then choice = 4
  300.             if choice = dnk.5 then choice = 5
  301.             if choice = dnk.6 then choice = 6
  302.             if choice = dnk.7 then choice = 7
  303.          end
  304.       otherwise NOP
  305.    end    /* of Select */
  306.    dnk_alert = ''
  307.    if do_not_kill = 1 then dnk_alert = '  (connection will stay up when finished)'
  308.    say ''
  309.    say 'Menu Selection: ' choice dnk_alert
  310.    say ''
  311. end    /* of Do Until Pos(choice, '1234567' || Escape) */
  312.  
  313. /*
  314. ====================
  315. A home\replies folder (empty) may be left behind as trash
  316. after execution of mail/news retrieval from some Yarn/Souper
  317. installations. We get rid of it if your setup of Yarn/Souper
  318. leaves one behind.
  319. ====================
  320. */
  321. replies_dir = home || '\replies'
  322. call SysRmDir replies_dir
  323.  
  324.    /* Fix the interrupted import */
  325. if choice = pos(choice, 'xxxxx6x') then
  326.    do
  327.       call fix_import
  328.       signal goodbye            /* Exit the program when done */
  329.    end
  330. if choice = pos(choice, 'xxxxxx7') then
  331.    do
  332.       call SysCls
  333.       say ''
  334.       say 'You selected to modify souper options.'
  335.       say ''
  336.       say 'We will first dial in.'
  337.       say ''
  338.       say 'After a connection is successfully established you will'
  339.       say 'be asked to select your one-time-only souper options.'
  340.       say ''
  341.       say 'When you are finished with that, another menu will pop'
  342.       say 'up asking if you want to get news or mail, or send posts.'
  343.       say ''
  344.       say 'To quit now, press Escape'
  345.       say 'Any other key starts the dialup connection or uses one already up'
  346.       if SysGetKey('NOECHO') = Escape then signal goodbye
  347.       else NOP
  348.     end
  349. call dialup_server
  350. call time('R')        /* start clock recording time on line */
  351.  
  352. /*
  353. =================
  354. These next conditionals process selections we made from the main menu.
  355. Choices 1-5 selected below from menu2 perform the identical functions
  356. to those for functions 1-5, respectively, selectable from main menu
  357. =================
  358. */
  359.       if choice = pos(choice, 'xxxxxx7') then
  360.          do
  361.             call souper_options
  362.             choice = menu2()
  363.          end
  364.       if choice = pos(choice, '1x3x5xx') then call import_mail
  365.       if choice = pos(choice, 'x23x5xx') then call import_news
  366.       if choice = pos(choice, 'xxx45xx') then call exporter
  367.  
  368. call kill_dialers_slip_ppp_slattach        /* Kill these and slattach, too */
  369.  
  370. call restore_zip    /* If sending went south on you, you can restore to send again */
  371. call toss_old_news
  372.  
  373. signal Depart                /* Exit and report times */
  374.  
  375. /*
  376. =================
  377. End of main program
  378. =================
  379. */
  380.  
  381. /*
  382. =======================================
  383. fatal_error_check()
  384.  
  385. We check for some obvious flaws in the data
  386. returned from YDPARMS_DAT
  387. =======================================
  388. */
  389.  
  390. fatal_error_check:
  391. service = translate(service)        /* Upper case */
  392.  
  393. if pos(connection_type, '134567') = 0 then    /* 2 is reserved for future use */
  394.    do
  395.       say 'Fatal error in' ydparms_dat '; the connection_type'
  396.       say 'can only be 1, or 3-7'
  397.       say ''
  398.       Abandon = 1
  399.    end
  400.  
  401. if connection_type = pos(connection_type, '13457') & dialup_string = '' then
  402.    do
  403.       say 'Fatal error in' ydparms_dat
  404.       say 'Dialup_string is blank.  Cannot be blank if connection_type is 1, 3-5, or 7.'
  405.       say ''
  406.       Abandon = 1
  407.    end
  408.  
  409. if service = '' then
  410.    do
  411.       say 'Possible error in' ydparms_dat '; SERVICE field is blank.'
  412.       say 'Usually would contain something like: PPP, SLIP, SL, etc.'
  413.    end
  414.  
  415. if pos(interface_removal, '012') = 0 then
  416.    do
  417.       say 'Fatal error in' ydparms_dat '; interface_removal'
  418.       say 'can only be 0, 1 or 2'
  419.       if pos(interface_removal, 'Oo') \=0 then
  420.          say 'You have the letter' pos(interface_removal, 'Oo') 'there now.'
  421.       say ''
  422.       Abandon = 1
  423.    end
  424.  
  425. /* Check if domain nameserver addresses are both blank.  If only
  426. on is, copy the other over to it.  Error only if both are missing. */
  427. if DNS = '' then DNS = DNS2
  428. if DNS2 = '' then DNS2 = DNS
  429. if DNS = '' & DNS2 = '' then
  430.    do
  431.       say 'Possible error: nothing in DNS or DNS2 fields in' ydparms_dat ||','
  432.       say 'DNS and DNS2 are the domain nameserver addresses (main and'
  433.       say 'alternate) in Decimal Dot notation.  At least one of these fields'
  434.       say 'must be populated.  It would look like: 150.203.23.247'
  435.       say ''
  436. end
  437.  
  438. if Abandon = 1 then
  439.    do
  440.       say 'Aborting...'
  441.       signal goodbye
  442.    end
  443. RETURN
  444.  
  445. /*
  446. =================
  447. get_current_connection()
  448.  
  449. (1)  Check whether slippm.exe, slip.exe, ppp.exe, in-joy.exe,
  450. IAK Dialer, ilink2.exe are running.  Are what is running the right
  451. processes for our connection_type and service (SLIP or PPP)?
  452. Of these processes:
  453.     SLIP.EXE
  454.     PPP.EXE
  455.     SLIPPM.EXE
  456.     IN-JOY.EXE
  457.     ILINK2.EXE
  458.     the IAK Dialer
  459.         whatever alt_dialer_exe is
  460.  
  461. Close down any that are not consistent with
  462. our connection_type.
  463.  
  464. Then determine: which ones are (left) running?
  465.  
  466.  
  467. (2)  Check for sl and ppp and other router interfaces
  468. ====================
  469. */
  470. get_current_connection:
  471. say 'Check for an existing connection, and whether it is correct for us:'
  472. say '   Active dialers? Active SLIP?  Active PPP?'
  473.  
  474. if connection_type = 1 then    /* IBM/Advantis IAK Dialer only */
  475.    do
  476.       service = 'SLIP'    /* must be SLIP for the IAK Dialer */
  477.       call close_down 'ppp'    /* ...because none of these should be running */
  478.       call close_down 'slippm'
  479.       call close_down 'in-joy'
  480.       call close_down 'ilink2'
  481.       if alt_dialer \= 'DIALER' then
  482.          call close_down alt_dialer
  483.    end
  484.  
  485. /* for connection_type 6 (pot luck) we check (almost) nothing */
  486. if connection_type = 6 then
  487.    do
  488.       if service = 'PPP' then call close_down 'slip'
  489.       if service = 'SLIP' then call close_down 'ppp'
  490.    end
  491.  
  492. if pos(connection_type, '45') \= 0,
  493.    & alt_dialer = 'SLIPPM' then
  494.    do
  495.       call close_down 'in-joy'
  496.       call close_down 'dialer'
  497.       call close_down 'ilink2'
  498.    end
  499.  
  500. if pos(connection_type, '45') \= 0,
  501.    & alt_dialer = 'IN-JOY' then
  502.    do
  503.       call close_down 'slip'    /* IN-JOY doesn't use this...*/
  504.       call close_down 'ppp'    /* ...or these...*/
  505.       call close_down 'slippm'
  506.       call close_down 'ilink2'
  507.       call close_down 'dialer'    /*...IAK Dialer */
  508.    end
  509.  
  510. if pos(connection_type, '45') \= 0,
  511.    & alt_dialer = 'ILINK2' then
  512.    do
  513.       call close_down 'in-joy'
  514.       call close_down 'dialer'
  515.       call close_down 'slippm'
  516.    end
  517.  
  518. if pos(connection_type, '45') \= 0,
  519.    & alt_dialer \= 'SLIPPM',
  520.    & alt_dialer \= 'ILINK2',
  521.    & alt_dialer \= 'DIALER',
  522.    & alt_dialer \= 'IN-JOY' then
  523.    do
  524.       call close_down 'slippm'
  525.       call close_down 'ilink2'
  526.       call close_down 'dialer'
  527.       call close_down 'in-joy'
  528.    end
  529.  
  530. if connection_type = 3 then    /* PPP.EXE or SLIP.EXE dialup string only */
  531.    do
  532.       if service = 'SLIP' then
  533.          call close_down 'ppp'
  534.       if service = 'PPP' then
  535.          call close_down 'slip'
  536.       call close_down 'slippm'
  537.       call close_down 'in-joy'
  538.       call close_down 'ilink2'
  539.       if alt_dialer \= 'PPP' & alt_dialer \= 'SLIP' then
  540.          call close_down alt_dialer
  541.    end
  542.  
  543.  
  544. /*
  545. ===============
  546. See what stuff related to dialers or dialup strings may
  547. be running
  548.  
  549. and
  550.  
  551. Poll the routers: e.g., is an sl or a ppp interface up?
  552. Note, however, that what is returned may not be
  553. currently active, and what is returned could represent
  554. the last occurrence not a present connection.
  555. Calls wait_for_interface(), which uses
  556. NETSTAT.EXE -r to poll.
  557. ===============
  558. */
  559.  
  560. /*
  561. ==================
  562. Below are flags.  They are set to 1 if a process is running
  563. or if an interface is up.  Initialize all to zero
  564. ==================
  565. */
  566.  
  567. slip_is_running = 0
  568. ppp_is_running = 0
  569. IAKdialer_is_running = 0
  570. slippm_is_running = 0
  571. ilink2_is_running = 0
  572. alt_dialer_is_running = 0
  573. slipexe_or_pppexe_running = 0
  574.  
  575. some_interf_up = 0
  576. ifprefix_interf_up = 0
  577.  
  578. /* are any of these running? */
  579. call is_slip_running    /* If so returns slip_is_running=1 */
  580. call is_ppp_running    /* If so returns ppp_is_running=1 */
  581. call is_slippm_running    /* If so returns slippm_is_running=1 */
  582. call is_ilink2_running    /* If so returns slippm_is_running=1 */
  583. call is_IAKdialer_running    /* If so returns IAKdialer_is_running=1 */
  584. call is_alt_dialer_running /* etcetera */
  585. if slip_is_running | ppp_is_running then slipexe_or_pppexe_running = 1
  586.  
  587. say '   Checking router interfaces...'
  588. /* Check for pppx or slx or lanx router interfaces
  589. we may not use this information, but this step is
  590. done here in anticipation of future uses */
  591.  
  592. call are_there_interfaces_up
  593.  
  594.  
  595. /*
  596. ==================
  597. Get path to TCPOS2.INI file.  Then get current_connection info from TCPOS2.INI.
  598. ==================
  599. */
  600.  
  601. tcpip_etc_path = value('etc', , 'OS2ENVIRONMENT')
  602. tcpos2_ini = tcpip_etc_path || '\' || 'tcpos2.ini'
  603. if stream(tcpos2_ini, 'c', 'query exists') = 0 then
  604.   say 'Couldn''t find' tcpos2_ini
  605.  
  606. /*
  607. ==========
  608. TCPOS2.INI inquiries
  609. ==========
  610. */
  611. current_connection_key = SysIni(tcpos2_ini, 'CONNECTION', 'CURRENT_CONNECTION')
  612.  
  613. /* strip final null char */
  614. current_connection_key = strip(current_connection_key, 'T', X1)
  615. userID_connected = SysIni(tcpos2_ini, 'CONNECTION', current_connection_key)
  616. userID_connected = strip(userID_connected, 'T', X1)
  617. parse var userID_connected user_ID ',' system_app
  618.  
  619. /*
  620. ====================
  621. Next we will decide if we need to dial or whether we
  622. can use what may already be established as a connection.
  623.  
  624. When dial = 1 we need to dial.  We will determine
  625. below whether, if we are already on line, we are online
  626. to the provider for this user installation or not.  If
  627. we cannot ID the provider as ours we simply close down
  628. SLIP, PPP, SLIPPM, and the IAK DIALER and redial.  First
  629. we set the dial flag (set dial = 1), then we determine
  630. if we should really dial.  If we are connected to our
  631. provider we zero the dial flag.
  632. ====================
  633. */
  634.  
  635. dial = 1    /* initialize it */
  636.  
  637. /*
  638. ====================
  639. We get parameters from the CONNECTION app of TCPOS2.INI and/or from
  640. subroutine nslookup_inq().   Thye latter uses nslookup.exe to interrogate the
  641. RESOLV file.   We compare those parameter to corresponding information in
  642. our YDPARMS_DAT.  We can make a pretty good (not perfect) assessment in
  643. this simple way whether we are connected to the right provider.
  644. ====================
  645. */
  646. if alt_dialer_is_running & some_interf_up & connection_type \= 7 then
  647.    do
  648.       call nslookup_inq
  649.       select
  650.          when connection_type = 1,
  651.             & IAKdialer_is_running,
  652.             & translate(user_id) = translate(login_id),
  653.             & translate(system_app) = 'ADVANTIS' then
  654.                do
  655.                   say 'Two beeps means' user_id 'is already connected to ADVANTIS.  Proceed.'
  656.                   call connected_signal
  657.                end
  658.  
  659.          when connection_type = 4,
  660.             & (slippm_is_running | ilink2_is_running),
  661.             & translate(user_ID) = translate(login_id) then
  662.                do
  663.                   say 'Two beeps means we are already logged in as'
  664.                   say user_id '(Pop_ID:' pop_id || ').  Proceed.'
  665.                   call connected_signal
  666.                end
  667.    
  668. /* IN-JOY:  How can we identify whether we are the right connection with IN-JOY
  669. if IN-JOY does not communicate with TCPOS2.INI?  We can set the interface name
  670. in setting up injoy so that it is unique and only applies to that connection being
  671. made with IN-JOY.  If we don't set up a unique name, we are no worse off than
  672. not checking at all.  make_if_list() returns with a string it generateswith all
  673. interfaces that it detects as up (including their metrics) and we look for
  674. interf_prefix in that string using the ReXX pos() function.  That would be a truly
  675. positive ID of the connection if the interf_prefix set in IN-JOY by the user for
  676. his/her host was unique.  Possible, but, alas, not everyone will do that.  So we
  677. also check the nameserver address against what is stored in IN-JOY as tranferred
  678. over to our YD_PARMS.DAT.
  679. */
  680.          when pos(connection_type, '45') \= 0 & alt_dialer = 'IN-JOY',
  681.             & pos(translate(interf_prefix), make_if_list()) \= 0,
  682.             & (dns_nslookup = dns | dns_nslookup = dns2) then
  683.                do
  684.                   say 'Two beeps means we are connected via' alt_dialer
  685.                   say 'to' domain_name || '.  Proceed...'
  686.                   call connected_signal
  687.                end
  688.    
  689.          when connection_type = 3,   /* slip.exe or ppp.exe dialer string */
  690.             & translate(user_ID) = translate(login_id) then
  691.                do
  692.                   say 'Two beeps means we are already logged in as'
  693.                   say user_id '(Pop_ID:' pop_id || ').  Proceed.'
  694.                   call connected_signal
  695.                end
  696.    
  697.          when connection_type = 6 then
  698.             dial = 0    /* Pot Luck */
  699.  
  700.          otherwise
  701.             say 'Connected, but to a provider or for a connection different than'
  702.             say 'the one for which this YARN user installation was configured.'
  703.             say 'We are closing down SLIP, PPP, SLIPPM and IAK Dialer, IN-JOY and'
  704.             say 'whatever alt_dialer was (if any are up), so we can dial up to our provider...'
  705.             say ''
  706.             dial = 1    /* we will dial when we hit dialup_server() */
  707.  
  708.             x = if do_not_kill /* save it */
  709.             do_not_kill = 0  /* temporarily to 0*/
  710.             call kill_all          /* ...so we can kill everything */
  711.             do_not_kill = x  /* and reset it to what it was */
  712.       end   /* of select */
  713.    end  /* of DO for if alt_dialer_is_running & some_interf_up & connection_type \= 7 */
  714.  
  715. if connection_type = 7 | \some_interf_up then
  716.    dial = 1
  717.  
  718. RETURN
  719.  
  720.  
  721. /*
  722. ===============
  723. connected_signal()
  724. Double-beep if connected
  725. ===============
  726. */
  727. connected_signal:
  728. say ''
  729. call beep 1000, 200
  730. call beep 32767, 25  /* Too high pitched, inaudible, an improvised pause. */ 
  731. call beep 1000, 200
  732. dial = 0    /* unset the flag: we do not need to dial up server */
  733. RETURN
  734.  
  735.  
  736. /*
  737. =====================
  738. directory_maintenance()
  739.  
  740. Some grunt work to get drives, directories we need.
  741. =====================
  742. */
  743.  
  744. directory_maintenance:
  745. home_drive = filespec('drive', home)
  746. parse var reply_packet rpname '.' ext
  747. yarn_outgoing_drive = filespec('drive', reply_packet)
  748. yarn_outgoing_dir = yarn_outgoing_drive || strip(filespec('path', reply_packet), 'T', '\')
  749.  
  750. call SysMkDir home || '\incoming'
  751. /* For temp storage of incoming mail and news */
  752.  
  753. RETURN
  754.  
  755. /*
  756. ================
  757.  routines use GO.EXE to let us determine whether
  758.     SLIP.EXE
  759.     PPP.EXE
  760.     SLIPPM.EXE
  761.     IN-JOY.EXE
  762.     ILINK2.EXE
  763.     DIALER.EXE
  764.     alt_dialer_exe (whatever it is)
  765. are running processes
  766. ================
  767. */
  768.  
  769. is_slip_running:
  770. signal off error
  771. slip_is_running = 0
  772. go_exe '-cp SLIP>NUL'    /* returns 1 if slip is running, 0 if not */
  773. If RC=1 then
  774.    do
  775.       slip_is_running = 1
  776.    end
  777. if local_error_trapping then signal on error
  778. RETURN
  779.  
  780. is_ppp_running:
  781. signal off error
  782. ppp_is_running = 0
  783. go_exe '-cp PPP>NUL'    /* returns 1 if ppp is running, 0 if not */
  784. If RC=1 then
  785.    do
  786.       ppp_is_running = 1
  787.    end
  788. if local_error_trapping then signal on error
  789. RETURN
  790.  
  791. is_slippm_running:
  792. signal off error
  793. slippm_is_running = 0
  794. go_exe '-cp SLIPPM>NUL'    /* returns 1 if slippm is running, 0 if not */
  795. If RC=1 then
  796.    do
  797.       slippm_is_running = 1
  798.    end
  799. if local_error_trapping then signal on error
  800. RETURN
  801.  
  802. is_ilink2_running:
  803. signal off error
  804. ilink2_is_running = 0
  805. go_exe '-cp ILINK2>NUL'    /* returns 1 if ilink2 is running, 0 if not */
  806. If RC=1 then
  807.    do
  808.       ilink2_is_running = 1
  809.    end
  810. if local_error_trapping then signal on error
  811. RETURN
  812.  
  813. is_IAKdialer_running:
  814. signal off error
  815. IAKdialer_is_running = 0
  816. go_exe '-cp DIALER>NUL'    /* returns 1 if IAK Dialer is running, 0 if not */
  817. If RC=1 then
  818.    do
  819.       IAKdialer_is_running = 1
  820.    end
  821. if local_error_trapping then signal on error
  822. RETURN
  823.  
  824. is_alt_dialer_running:
  825. signal off error
  826. alt_dialer_is_running = 0
  827. go_exe '-cp' alt_dialer '>NUL'    /* returns 1 if running, 0 if not */
  828. If RC=1 then
  829.    do
  830.       alt_dialer_is_running = 1
  831.    end
  832. if local_error_trapping then signal on error
  833. RETURN
  834.  
  835. /*
  836. ====================
  837. This is the menu that comes up after we have made
  838. one-time-only changes (i.e., for this session only) to the
  839. souper command-line options
  840. ====================
  841. */
  842.  
  843. menu2:
  844.    say ''
  845.    say '   Any changed option settings are in force for this session only.'
  846.    say ''
  847.    say 'Press:'
  848.    say '1  Only import Mail'
  849.    say '2  Only import News Articles'
  850.    say '3  Only import, but both Mail AND News'
  851.    say '4  Only export (send Mail, Posts, Replies, and Follow-ups)'
  852.    say '5  Everything: Get mail and news AND send Posts, Replies, and Follow-ups'
  853.    say 'Pressing Esc key exits now.  Enter Selection:'
  854.  
  855. do until pos(choice, '12345') \= 0 
  856.    choice = SysGetKey('NOECHO')
  857.    select
  858.       when choice = Escape then signal goodbye
  859.       when pos(choice, '12345') = 0 then
  860.          do
  861.             say ''
  862.             say 'Selection' choice || '.  Must be 1-5 or Escape key.  Try again...'
  863.             say ''
  864.         end
  865.       otherwise NOP
  866.    end
  867.    say ''
  868.    say 'Selection: ' choice
  869.    say ''
  870. end
  871. RETURN choice
  872.  
  873. /*
  874. =========================================================
  875. dialup_server()
  876.  
  877. Starts dialers.  As dialer is starting up and logging in,
  878. wait_for_interface() starts a timed wait.  When we connect,
  879. the wait_for_interface() senses a new ppp, slip, etc.
  880. interface by interpreting the output of netstat.exe run with the -r
  881. option, and this subroutine ends. If we time out, the
  882. wait_for_interface() senses that and we exit YARNDIAL.
  883.  
  884. We start by reassigning some variables depending upon the
  885. connection_type, then we start the actual dialup.
  886.  
  887. The dial variable was assigned 0 or 1 in the get_current_connection()
  888. subroutine.  If dial=1 we must dial, if dial=0, we were connected to
  889. the right provider already and do not dial.
  890.  
  891. =========================================================
  892. */
  893. dialup_server:
  894. /*
  895. =============
  896. connection_type 1 is for IAK Dialer only
  897. =============
  898. */
  899. if connection_type = 1 then                /* IAK Dialer only */
  900.    do
  901.       say 'Connecting to Advantis via the IAK Dialer...'
  902. /* Now set or reset the NNTPSERVER environment variable to default_news */
  903.       x = value('NNTPSERVER', default_news, 'OS2ENVIRONMENT')
  904.       if dial then
  905.          do
  906.             say login_id 'dialing' account '<password> via use of IAK Dialer' 
  907.          end
  908.    end      /* if connection_type = 1 */
  909.  
  910. if pos(connection_type, '34') \= 0 then
  911.    do
  912. /* Set or reset the NNTPSERVER environment variable to default_news */
  913.       x = value('NNTPSERVER', default_news, 'OS2ENVIRONMENT')
  914.       if dial then
  915.          do
  916.             if connection_type = 3 then say 'Dialing with a PPP.EXE or SLIP.EXE dialup string'
  917.             if connection_type = 4 then say 'Dialing' host_app 'with' alt_dialer_exe
  918.          end
  919.    end    /* if connection_type 3 or 4 */
  920.  
  921. /*
  922. =============
  923. For connection_type 6 (especially), but also for
  924. 5 and 7, we are a bit more flexible about where
  925. some parms we need may be found in YD_PARMS.DAT
  926. =============
  927. */
  928. if pos(connection_type, '567') then
  929.    do
  930. /* Set or reset the NNTPSERVER environment variable to default_news */
  931.       x = value('NNTPSERVER', default_news, 'OS2ENVIRONMENT')
  932.  
  933.       if connection_type = 5 then
  934.          do
  935.             say 'YD_PARMS.DAT was manually configured: Dialing with'
  936.             say 'dialup_string in YD_PARMS.DAT...'
  937.          end
  938.  
  939.       if connection_type = 6 then
  940.          do
  941.             say 'Will not attempt to validate vs. parameters in YD_PARMS.DAT'
  942.             say 'Trying to use any currently established connection...'
  943.          end
  944.  
  945.       if connection_type = 7 then
  946.          do
  947.             say 'Will not attempt to validate vs. parameters in YD_PARMS.DAT'
  948.             say 'Dialing with dialup_string in YD_PARMS.DAT...'
  949.          end
  950.    end       /* if connection_type 5, 6 or 7 */
  951.  
  952. /*
  953. ===================
  954. Dial up.
  955. Unless we are connection_type 6, we wait for
  956. sl0 or ppp0 interface before going on to get/send
  957. mail or news.  Or if we time out after 'wait'
  958. seconds, we exit
  959. ===================
  960. */
  961. if connection_type = 1 & dial then
  962.    do
  963.      call make_if_list
  964.      interpret dialup_string
  965.  
  966.  /* 'wait' = seconds to wait for a connect */
  967.       call wait_for_interface wait, 0
  968.       if \found_interface then
  969.          do
  970.             timeout = 1
  971.             say ''
  972.             say 'Dialer timed out.  Exiting...'
  973.             call time('R')  /* No connection.  We zero the elapsed-time clock */
  974.             if local_error_trapping then signal on error
  975.             signal goodbye
  976.          end
  977.     end
  978.  
  979. if pos(connection_type, '3457') \=0 & dial then
  980.    do
  981.       call make_if_list
  982.       interpret dialup_string
  983.       call wait_for_interface wait, 0
  984.       if \found_interface then
  985.          do
  986.             timeout = 1
  987.             say ''
  988.             say 'Dialer timed out.  Exiting...'
  989.             call time('R')
  990.             if local_error_trapping then signal on error
  991.             signal goodbye
  992.          end
  993.    end
  994. RETURN
  995.  
  996. /*
  997. ============================
  998. import_mail()
  999. import_news()
  1000. exporter()
  1001.  
  1002. Believe it or not, executing these three subroutines
  1003. are the substance of YarnDial.  The other 90% of
  1004. this exercise is fluff.
  1005. ============================
  1006. */
  1007.  
  1008. import_mail:
  1009. call nslookup_inq
  1010. home_drive
  1011. 'cd' home || '\incoming'    
  1012. say 'You are now importing mail from' popsrvr
  1013. signal off error
  1014. signal off failure
  1015. souper_exe souper_getmail_std_options getmail_xtra_options popsrvr pop_id pop_pwd
  1016. zip_exe 'soup.zip areas *.msg'
  1017. import_exe 'soup.zip'
  1018. if local_error_trapping then signal on error
  1019. if local_error_trapping then signal on failure
  1020. say ''
  1021. RETURN
  1022.  
  1023. import_news:
  1024. home_drive
  1025. 'cd' home || '\incoming'
  1026. say 'You are now importing news from' default_news
  1027. signal off error
  1028. signal off failure
  1029. souper_exe souper_getnews_std_options getnews_xtra_options default_news pop_id pop_pwd
  1030. zip_exe 'soup.zip areas *.msg'
  1031. import_exe 'soup.zip'
  1032. if local_error_trapping then signal on error
  1033. if local_error_trapping then signal on failure
  1034. say ''
  1035. RETURN
  1036.  
  1037. exporter:
  1038. say crlf || 'You are now exporting posts, replies, and follow-ups'
  1039. say 'to' mail_gw
  1040. /* if a reply-packet exists, send mail */
  1041. if stream(reply_packet, 'c', 'query exists') \= '' then
  1042.    do
  1043.       yarn_outgoing_drive    /* Change to outgoing drive and directory */
  1044.       'cd' yarn_outgoing_dir
  1045.       'copy' reply_packet rpname || '.BAK>nul'
  1046.       unzip_exe reply_packet
  1047.       signal off error
  1048.       signal off failure
  1049.       souper_exe souper_send_std_options send_xtra_options mail_gw pop_id pop_pwd
  1050.       'erase' reply_packet
  1051.    end
  1052. else    /* tell us nothing waiting to be sent */
  1053.    do
  1054.       say ''
  1055.       say reply_packet 'not found.'
  1056.       say 'Means no replies are waiting to be sent.'
  1057.       replies_zip = 0
  1058.    end
  1059. if local_error_trapping then signal on error
  1060. if local_error_trapping then signal on failure
  1061. RETURN
  1062.  
  1063. /*
  1064. =====================
  1065. catch()
  1066.  
  1067. For catching up on news.  Sets the Howmany variable.
  1068. Howmany is number of unread news articles (max) we
  1069. retrieve from each newsgroup (all the older ones
  1070. in each newsgroup are marked as read)
  1071. =====================
  1072. */
  1073. Catch:
  1074. HowMany = ''
  1075. call SysCls
  1076. say 'News catchup was selected'
  1077. say ''
  1078. say ''
  1079. say 'Mark every article not yet downloaded in'
  1080. say 'each newsgroup as read except for the last n articles.'
  1081. do until DataType(HowMany,'W')
  1082.    say 'Enter n (Max number to be transferred to you).'
  1083.    prompt = 'It must be a whole number  (Esc exits now):'
  1084.    say prompt
  1085.    parse value SysCurPos() with row col
  1086.    row  = row - 1
  1087.    col = length(prompt) + 2
  1088.    call SysCurPos row, col
  1089.    pull HowMany .
  1090.    if HowMany = Escape then
  1091.       do
  1092.          say 'Esc pressed, Quitting...'
  1093.          signal goodbye
  1094.       end
  1095.    if DataType(HowMany) = 0 then
  1096.       say 'Whole number only. Try Again.' 
  1097. end
  1098. RETURN
  1099.  
  1100. fix_import:
  1101. /*
  1102. ===================
  1103. if for some reason the imported mail or news files
  1104. were not zipped and/or they were not imported into
  1105. YARN repositories correctly (for example, if your
  1106. machine crashed or if you had yarn running while
  1107. SOUPER was fetching them), this option may be able
  1108. to zip into soup.zip any that were unzipped at the
  1109. time, and will process the soup.zip and import the
  1110. messages.  In case YARN's history file might have
  1111. become corrupted in the process or has independently
  1112. become corrupted, it will also (try to) rebuild it.
  1113.  
  1114. Before we do anything, though, we kill slip, ppp,
  1115. IAKdialer, etc., so we are doing whatever we do (which
  1116. takes a long time) while off-line. 
  1117. =================
  1118. */
  1119. say 'If on-line, we will get off line.  This may take several seconds...'
  1120. call kill_dialers_slip_ppp_slattach        /* Kill these and slattach, too */
  1121.                         /* and in-joy if we are connection_type 4 */
  1122.  
  1123. say crlf || 'IMPORTING WAS INTERRUPTED? NEED TO REBUILD YARN History File?'
  1124. say 'If either you did not complete the importing of news or mail and/or'
  1125. say 'if YARN''s History File has become corrupted, we can now try to complete'
  1126. say 'the importing of mail and news and also do a YARN History File rebuild.'
  1127. say 'The rebuild may take some time...'
  1128. say ''
  1129. say 'Don''t bother with this unless you think you have a problem or fetching'
  1130. say 'and importing of mail/news was interrupted.' 
  1131. say ''
  1132. say 'CTRL-Q quits now without doing anything.  Any other key continues: '
  1133.  
  1134. if SysGetKey('NOECHO') = ctrl_Q then signal Goodbye 
  1135.  
  1136. home_drive
  1137. 'cd' home || '\incoming'    
  1138. signal off failure
  1139. signal off notready
  1140. signal off error
  1141. zip_exe 'soup.zip areas *.msg'
  1142. if stream('soup.zip', 'c', 'query exists') \= '' then    /* scrub import if no zipfile */
  1143.    do
  1144.       import_exe 'soup.zip'
  1145.    end
  1146. if local_error_trapping then signal on failure
  1147. if local_error_trapping then signal on notready
  1148. if local_error_trapping then signal on error
  1149. rebuild_exe '-s'        /*fixes spool file, rebuilds history file */
  1150. rebuild_exe '-o'        /* rebuilds history and overview files */
  1151. say ''
  1152. RETURN
  1153.  
  1154. kill_dialers_slip_ppp_slattach:    /* kill these, and tell us about it */
  1155.  
  1156. say ''
  1157. if \do_not_kill then
  1158.    do
  1159.       say 'Killing dialer(s), slip.exe, ppp.exe, etc., if up...'
  1160.       call kill_all    /* next routine does the contract */
  1161.       say 'We are off-line now.'
  1162.    end
  1163. else
  1164.    do
  1165.       say 'Beeping to remind you that YOU MAY STILL BE CONNECTED!'
  1166.       say 'When ready to disconnect, run LOGOFF.CMD or close down dialer.'
  1167.       call beep 1000, 200
  1168.       call beep 32767, 25  /* Too high pitched, inaudible, an improvised pause. */ 
  1169.       call beep 1000, 200
  1170.    end
  1171. say ''
  1172. t = time('E')            /* elapsed time, souper processes only */
  1173. RETURN
  1174.  
  1175. kill_all:        /* calls to this routine kill everything quietly */
  1176. call close_down 'DIALER'
  1177. call close_down 'SLIP'
  1178. call close_down 'PPP'
  1179. call close_down 'SLATTACH'
  1180. call close_down 'SLIPPM'
  1181. call close_down 'ILINK2'
  1182. if alt_dialer \= 'DIALER',
  1183.    & alt_dialer \= 'SLIP',
  1184.    & alt_dialer \= 'PPP',
  1185.    & alt_dialer \= 'SLIPPM',
  1186.    & alt_dialer \= 'ILINK2',
  1187.    & alt_dialer \= 'IN-JOY' then
  1188.       call close_down alt_dialer
  1189. if stream(killjoy_exe, 'c', 'query exists') \= '' then
  1190.    do
  1191.       killjoy_exe
  1192.       call SysSleep 2    /* settle time */
  1193.    end
  1194. call close_down 'IN-JOY' 
  1195. call SysSleep 2        /* just in case, wait a bit and re-kill */
  1196. call close_down 'DIALER'
  1197. call close_down 'SLIP'
  1198. call close_down 'PPP'
  1199. call close_down 'SLATTACH'
  1200. call close_down 'SLIPPM'
  1201. call close_down 'ILINK2'
  1202. if alt_dialer \= 'DIALER',
  1203.    & alt_dialer \= 'SLIP',
  1204.    & alt_dialer \= 'PPP',
  1205.    & alt_dialer \= 'SLIPPM',
  1206.    & alt_dialer \= 'ILINK2',
  1207.    & alt_dialer \= 'IN-JOY' then
  1208.       call close_down alt_dialer
  1209. if stream(killjoy_exe, 'c', 'query exists') \= '' then
  1210.    do
  1211.       killjoy_exe
  1212.       call SysSleep 2    /* settle time */
  1213.    end
  1214. call close_down 'IN-JOY' 
  1215. if interface_removal \= 0 then
  1216.    call routings_to_hosts(interf_prefix)    /* and clear out interfaces */
  1217. RETURN
  1218.  
  1219.  
  1220. /*
  1221. =========================================
  1222. close_down(process)
  1223.  
  1224. Close down a process (such as slip or ppp or slippm) with
  1225. GO.EXE using the -ka option kills all instances of 'process'.
  1226. No harm done if 'process' not running  and we try to close it down.
  1227. =========================================
  1228. */
  1229. close_down:
  1230. parse upper arg process
  1231. signal off error
  1232. go_exe '-cp' process '>NUL'    /* returns RC=1 if process is running and 0 if not */
  1233. if RC=1 & process = 'DIALER' then
  1234.    do
  1235.       call is_IAKdialer_running
  1236.       if IAKdialer_is_running then 
  1237.          do
  1238. /* Only try to close this way if IAK duller is confirmed to be running */
  1239.             process '-c' /* hope IAK dialer is at least v 1.33 where -c option supported */
  1240.             call SysSleep 2 /* settle time, IAK Dialer is funny */
  1241.             say '   If you lost this window for a few seconds or just heard a beep'
  1242.             say '   that is normal for closing down certain versions of IAK Dialer.'
  1243.             say '   Completing shutdown may take a few moments...'
  1244.          end
  1245.    end
  1246. /* try to shut down in-joy with IN-JOY's own killjoy.exe */
  1247. if RC=1 & process = 'IN-JOY' then
  1248.    do
  1249.       if stream(killjoy_exe, 'c', 'query exists') \= '' then killjoy_exe
  1250.       call SysSleep 2    /* settle time */
  1251.    end
  1252. go_exe '-ka' process '>NUL'  /* do a kill whether running or not */
  1253. if local_error_trapping then signal on error
  1254.  
  1255. RETURN
  1256.  
  1257. /*
  1258. =================
  1259. routings_to_hosts(interf_prefix)
  1260.  
  1261. Only called if interface_removal is non-zero.
  1262.  
  1263. Examines routing table host routes reported out by running
  1264.     netstat -r
  1265. and then
  1266. if interface_removal = 1
  1267.     and if IN-JOY is the dialer and if the interf_prefix is IN-JOY's,
  1268.     deletes that routing entry.
  1269. if interface_removal = 2
  1270.     whatever the dialer and interf_prefix deletes all routing entries.
  1271.  
  1272.  
  1273. Why do this?  IN-JOY sometimes leaves a phantom routing in the tables
  1274. and it persists, once there, when other dialers are started after
  1275. that happens.
  1276. =================
  1277. */
  1278. routings_to_hosts:
  1279. parse arg if_prefix
  1280. if_prefix = translate(if_prefix)
  1281. ifp_length = length(if_prefix)
  1282.  
  1283. 'netstat -r | rxqueue'    /* send output to the queue */
  1284. do queued()
  1285.    dest = ''
  1286.    rtr = ''
  1287.    interf = ''
  1288.    parse pull netstat_line
  1289.    parse var netstat_line dest rtr .
  1290.    dest = strip(dest, 'B')
  1291.    rtr = strip(rtr, 'B')
  1292.    interf = word(netstat_line, words(netstat_line))
  1293.    interf = strip(interf, 'B')
  1294.    select
  1295. /* A headings line (first word is 'destination')? Discard the line */
  1296.       when translate(dest) = 'DESTINATION' then iterate
  1297.  
  1298. /* Blank dest or rtr? Discard the line, 'route delete' won't work */
  1299.       when dest = '' | rtr = '' then iterate
  1300.  
  1301. /* If interface_removal=1, IN-JOY, but not our interface,
  1302. also discard the line */
  1303.       when interface_removal = 1 & alt_dialer = 'IN-JOY',
  1304.          & translate(left(interf, ifp_length)) \= if_prefix then
  1305.             iterate
  1306.  
  1307. /* If interface_removal=1 and not IN-JOY,
  1308. discard the line */
  1309.       when interface_removal = 1 & alt_dialer \= 'IN-JOY' then iterate
  1310.  
  1311. /* Anything else, delete the routing */
  1312.       otherwise
  1313.          'route -h delete' dest rtr
  1314.    end    /* of Select */
  1315. end    /* of Do queued() */
  1316. RETURN
  1317.  
  1318.  
  1319.  
  1320. /*
  1321. =====================
  1322. restore_zip()
  1323.  
  1324. Chance to restore zipfile if sending didn't
  1325. seem to go right
  1326. =====================
  1327. */
  1328.  
  1329. restore_zip:
  1330. rpname_bak = rpname || '.BAK'
  1331. /* if we were exporting posts and replies and if there was a reply_packet */
  1332. if pos(choice, 'xxx45xx') \= 0 & timeout = 0 & replies_zip then
  1333.    do
  1334.       say '     If you got an error sending posts and replies, press'
  1335.       say '     CONTROL-R now to restore' reply_packet
  1336.       say '     for re-transmission in a later session, but do this'
  1337.       say '     only if you got an error.'
  1338.       say '     Otherwise press any other key to continue exiting.'
  1339.       if SysGetKey('NOECHO') = ctrl_R then
  1340.          if stream(rpname_bak, 'c', 'query exists') \= 0 then  
  1341.             do
  1342.                say 'Restoring' reply_packet
  1343.                'copy' rpname_bak reply_packet '>nul'
  1344.            end
  1345.       else say 'No' rpname_bak 'to restore'
  1346.    end
  1347. RETURN
  1348.  
  1349. /*
  1350. ================
  1351. toss_old_news()
  1352.  
  1353. Chance to remove old news using the expire program
  1354. ===============
  1355. */
  1356. toss_old_news:
  1357.    Prompt = 'Remove old (expired) yarn messages (Y/N)?'
  1358.    say prompt
  1359.    parse value SysCurPos() with row col
  1360.    row  = row - 1
  1361.    col = length(prompt) + 2
  1362.    call SysCurPos row, col
  1363.    if translate(SysGetKey('NOECHO')) = 'Y' then
  1364.       do
  1365.          say ''
  1366.          say 'Removing expired news' || crlf
  1367.          expire_exe '-o'    /* Remove old messages */
  1368.       end
  1369. RETURN
  1370.  
  1371. /*
  1372. ===================
  1373. connect_stats()
  1374.  
  1375. How long were we on line retrieving or sending stuff?
  1376. ==================
  1377. */
  1378. connect_stats:
  1379.    say '   Retrieval and sending of news and/or mail took' trunc((t/60), 2) 'mins' 
  1380. RETURN
  1381.  
  1382.  
  1383. /*
  1384. ==========
  1385. nslookup_inq()
  1386. Inquiries made running nslookup
  1387.  
  1388. If run while connected, we can get name of domain
  1389. and its nameserver address.  If not connected, we get
  1390. the default domain name back but no nameserver address is
  1391. resolved.  Thus, if we get both a domain name back and a
  1392. nameserver address we are connected and if both agree with
  1393. what our YD_PARMS.DAT file has, we are connected to
  1394. the right one (to a good probability , but then, nothing's perfect,
  1395. is it?).
  1396.  
  1397. So we don't screw up too badly, we use this  only for IN-JOY
  1398. dialer and we only check, in get_current_connection(), the
  1399. nameserver decimal dot address returned by nslookup.exe vs.
  1400. what is in YDPARMS.DAT.
  1401. ==========
  1402. */
  1403. nslookup_inq:
  1404. 'nslookup -all' domain_name '2>nul | rxqueue'
  1405. domain_nslookup = ''
  1406. dns_nslookup = ''
  1407.  
  1408. do queued()
  1409. firstword = ''
  1410. rest = ''
  1411.    parse pull line
  1412.    parse var line firstword '=' remainder
  1413.    firstword = strip(firstword, 'B')
  1414.    remainder = strip(remainder, 'B')
  1415.    if translate(firstword) = 'DOMAIN' then
  1416.      do
  1417.         domain_nslookup = remainder
  1418.         domain_nslookup = strip(domain_nslookup, 'B')
  1419.      end 
  1420.    parse var line  firstword ':' remainder length(remainder)
  1421.    firstword = strip(firstword, 'B')
  1422.    remainder = strip(remainder, 'B')
  1423.    if translate(firstword) = 'ADDRESS' then
  1424.       do
  1425.          dns_nslookup = remainder
  1426.          dns_nslookup = strip(dns_nslookup, 'B')
  1427.       end
  1428. end
  1429. RETURN
  1430.  
  1431. /*
  1432. ===================
  1433. parms_from_ydparms_dat()
  1434.  
  1435. Assign parameters based on what is in YDPARMS_DAT
  1436. ==================
  1437. */
  1438. parms_from_ydparms_dat:
  1439. /* Get parms from ydparms_dat */
  1440. n = find_equate_lines_in_datafile(ydparms_dat)
  1441. i = 1
  1442.  
  1443. /*
  1444. ====================
  1445. Strip out all leading and trailing blanks and tabs
  1446. from parsed left and right sides of the equal sign.
  1447. Leave any internal ones alone
  1448. ====================
  1449. */
  1450.  
  1451. do until i = n
  1452.    parse var line.i parm.i '=' val.i
  1453.    parm.i = translate(parm.i)
  1454.    do until parm.i = stripped_parm.i & val.i = stripped_val.i
  1455.       stripped_parm.i = strip(parm.i, 'B')
  1456.       parm.i = strip(stripped_parm.i, 'B', tab)
  1457.       stripped_val.i = strip(val.i, 'B')
  1458.       val.i = strip(stripped_val.i, 'B', tab)
  1459.   end
  1460.    if abbrev(line.i, '#') then NOP
  1461.    else
  1462.           /* set up our variables */
  1463.       select
  1464.          when parm.i = 'HOME' then HOME = val.i 
  1465.          when parm.i = 'YARN' then YARN = val.i
  1466.          when parm.i = 'CONNECTION_TYPE' then connection_type = val.i
  1467.          when parm.i = 'INTERFACE_REMOVAL' then interface_removal = val.i
  1468.          when parm.i = 'HOST_APP' then host_app = val.i
  1469.          when parm.i = 'INTERF_PREFIX' then interf_prefix = val.i
  1470.          when parm.i = 'DIALUP_STRING' then dialup_string = val.i
  1471.          when parm.i = 'DO_NOT_KILL_CONNECTION' then do_not_kill_connection = val.i
  1472.          when parm.i = 'DNK_STRING' then dnk_string = val.i
  1473.          when parm.i = 'USER' then user = val.i
  1474.          when parm.i = 'HOST' then host = val.i
  1475.          when parm.i = 'ACCOUNT' then account = val.i
  1476.          when parm.i = 'ZIP_EXE' then zip_exe = val.i
  1477.          when parm.i = 'UNZIP_EXE' then unzip_exe = val.i
  1478.          when parm.i = 'REPLY_PACKET' then reply_packet = val.i
  1479.          when parm.i = 'SOUPER_EXE' then souper_exe = val.i 
  1480.          when parm.i = 'IMPORT_EXE' then import_exe = val.i 
  1481.          when parm.i = 'EXPORT_EXE' then export_exe = val.i 
  1482.          when parm.i = 'EXPIRE_EXE' then expire_exe = val.i 
  1483.          when parm.i = 'REBUILD_EXE' then rebuild_exe = val.i
  1484.          when parm.i = 'KILLJOY_EXE' then killjoy_exe = val.i
  1485.          when parm.i = 'ALT_DIALER_EXE' then alt_dialer_exe = val.i
  1486.          when parm.i = 'GO_EXE' then go_exe = val.i
  1487.          when parm.i = 'SOUPER_GETMAIL_STD_OPTIONS'
  1488.             then souper_getmail_std_options = val.i 
  1489.          when parm.i = 'GETMAIL_XTRA_OPTIONS'
  1490.             then getmail_xtra_options = val.i 
  1491.          when parm.i = 'SOUPER_GETNEWS_STD_OPTIONS'
  1492.             then souper_getnews_std_options = val.i 
  1493.          when parm.i = 'GETNEWS_XTRA_OPTIONS'
  1494.             then getnews_xtra_options = val.i 
  1495.          when parm.i = 'SOUPER_SEND_STD_OPTIONS'
  1496.             then souper_send_std_options = val.i 
  1497.          when parm.i = 'SEND_XTRA_OPTIONS'
  1498.             then send_xtra_options = val.i
  1499.          when parm.i = 'WAIT' then wait = val.i
  1500.          when parm.i = 'ASK' then ASK = val.i
  1501.          when parm.i = 'IS1' then IS1 = val.i
  1502.          when parm.i = 'IS2' then IS2 = val.i
  1503.          when parm.i = 'RS1' then RS1 = val.i
  1504.          when parm.i = 'RS2' then RS2 = val.i
  1505.          when parm.i = 'FS1' then FS1 = val.i
  1506.          when parm.i = 'FS2' then FS2 = val.i
  1507.          when parm.i = 'PIN' then PIN = val.i
  1508.          when parm.i = 'PROVIDER' then PROVIDER = val.i
  1509.          when parm.i = 'LOGIN_ID' then LOGIN_ID = val.i
  1510.          when parm.i = 'PWD' then PWD = val.i
  1511.          when parm.i = 'SAVE_PWD' then SAVE_PWD = val.i
  1512.          when parm.i = 'PHONE_NUMBER' then PHONE_NUMBER = val.i
  1513.          when parm.i = 'HANGUP' then HANGUP = val.i
  1514.          when parm.i = 'SCRIPT' then SCRIPT = val.i
  1515.          when parm.i = 'SERVICE' then SERVICE = val.i
  1516.          when parm.i = 'YOURIP' then YOURIP = val.i
  1517.          when parm.i = 'DESTIP' then DESTIP = val.i
  1518.          when parm.i = 'NETMASK' then NETMASK = val.i
  1519.          when parm.i = 'MTU_SIZE' then MTU_SIZE = val.i
  1520.          when parm.i = 'VJ_COMP' then VJ_COMP = val.i
  1521.          when parm.i = 'PRIMARY_INF' then PRIMARY_INF = val.i
  1522.          when parm.i = 'HOSTNAME' then HOSTNAME = val.i
  1523.          when parm.i = 'DOMAIN_NAME' then DOMAIN_NAME = val.i
  1524.          when parm.i = 'DNS' then DNS = val.i
  1525.          when parm.i = 'DNS2' then DNS2 = val.i
  1526.          when parm.i = 'DEFAULT_NEWS' then DEFAULT_NEWS = val.i
  1527.          when parm.i = 'DEFAULT_WWW' then DEFAULT_WWW = val.i
  1528.          when parm.i = 'DEFAULT_GOPHER' then DEFAULT_GOPHER = val.i
  1529.          when parm.i = 'MAIL_GW' then MAIL_GW = val.i
  1530.          when parm.i = 'POPSRVR' then POPSRVR = val.i
  1531.          when parm.i = 'REPLY_DOMAIN' then REPLY_DOMAIN = val.i
  1532.          when parm.i = 'REPLY_ID' then REPLY_ID = val.i
  1533.          when parm.i = 'POP_ID' then POP_ID = val.i
  1534.          when parm.i = 'POP_PWD' then POP_PWD = val.i
  1535.          when parm.i = 'MODEM_TYPE' then MODEM_TYPE = val.i
  1536.          when parm.i = 'COMPORT' then COMPORT = val.i
  1537.          when parm.i = 'BAUD' then BAUD = val.i
  1538.          when parm.i = 'DATABITS' then DATABITS = val.i
  1539.          when parm.i = 'PARITY' then PARITY = val.i
  1540.          when parm.i = 'DIAL_MODE' then DIAL_MODE = val.i
  1541.          when parm.i = 'PREFIX' then PREFIX = val.i
  1542.          when parm.i = 'PREFIX_ANS' then PREFIX_ANS = val.i
  1543.          when parm.i = 'INIT' then INIT = val.i
  1544.          when parm.i = 'INIT2' then INIT2 = val.i
  1545.          when parm.i = 'DISABLE' then DISABLE = val.i
  1546.          when parm.i = 'DISABLE_SEQ' then DISABLE_SEQ = val.i
  1547.          when parm.i = 'DIAL_PREFIX' then DIAL_PREFIX = val.i
  1548.          when parm.i = 'AUTOSTART' then AUTOSTART = val.i
  1549.          when parm.i = 'TOTAL_CONNECT' then TOTAL_CONNECT = val.i
  1550.          otherwise NOP
  1551.       end
  1552.    i = i + 1
  1553. end
  1554.  
  1555. o21 = '&\<=>|()! *+"''-/,#$%.0123456789:;?'
  1556. o22 = '@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^'
  1557. o23 = '_`abcdefghijklmnopqrstuvwxyz{}~'
  1558. e21 = '&\<=>|()u *+"''-/,MI$kUHgW[_A5%w~Fh'
  1559. e22 = 't?K^l0jJP{98xBadb1nZimRyY]4}`o'
  1560. e23 = 'E;67V@vS:C.sNGzcefQpqTr!2#XDLO3'
  1561.  
  1562. pop_pwd = translate(pop_pwd, e21||e22||e23, o21||o22||o23)
  1563. pwd = translate(pwd, e21||e22||e23, o21||o22||o23)
  1564. RETURN
  1565.  
  1566. /*
  1567. ======================
  1568. find_equate_lines_in_datafile()
  1569.  
  1570.  backslash ('\') as the final character in the datafile
  1571. means the line is continued on the line following.  First
  1572. we reconstitute those lines that have continuations,
  1573. then we search through those lines for an '=' sign as
  1574. other than the first character.  We eliminate from
  1575. consideration any line with a '#' as the first character
  1576. as that signifies the line is a comment line.
  1577. ======================
  1578. */
  1579. find_equate_lines_in_datafile:
  1580. arg filename
  1581. n = 1
  1582. do while lines(filename) > 0
  1583.    data_line.n = linein(filename)
  1584.    select
  1585.       when right(data_line.n, 1) = '\' then    /* concatenating continuations */
  1586.          do until right(data_line.n, 1) \= '\'
  1587.             data_line_n_with_right_slash_stripped =,
  1588.                   strip(right(data_line.n,1), 'T', '\')
  1589.             next_data_line = linein(filename)
  1590.             data_line.n = data_line_n_with_right_slash_stripped || next_data_line
  1591.          end
  1592.  
  1593. /* only lines without a leading # and with an = qualify */
  1594.       when pos('=', data_line.n) > 0 & \abbrev(data_line.n, '#') then
  1595.          do
  1596.             line.n = data_line.n
  1597.             n = n + 1
  1598.          end
  1599.       otherwise NOP
  1600.    end
  1601. end
  1602. RETURN n
  1603.  
  1604. /*
  1605. ====================
  1606. souper_options()
  1607.  
  1608. Chance to modify the souper options on a
  1609. one-time-only basis
  1610. ====================
  1611. */
  1612. souper_options:
  1613. call SysCls
  1614. getnews_xtra_options = '' /* the defaults */
  1615. getmail_xtra_options = ''
  1616. send_xtra_options = ''
  1617. option1 = ''
  1618. option2 = ''
  1619. option3 = ''
  1620. option4 = ''
  1621.  
  1622. say ''
  1623. say 'SOUPER OPTIONS SCREEN'
  1624. say 'You can select these as one-time-only options when souper runs.'
  1625. do until opts = 6
  1626.    say ''
  1627.    say 'Press:'
  1628.    say '  1 Set maximum news packetsize (default is 2048KB [2.048MB])'
  1629.    say '  2 Do not retrieve newsgroup articles containing more than set'
  1630.    say '    number of lines in the body (default is: no limit)'
  1631.    say '    You get to set the number of lines.'
  1632.    say '  3 Do catchup on news.  Mark all as read except last m unread'
  1633.    say '    news articles in each group.  You set m.'
  1634.    say '  4 For mail: read-only.  Do not empty POP3 mailbox or update NEWSRC file'
  1635.    say '  5 Default all four of the above.'
  1636.    say '  6 DONE.  (MUST press 6 to exit this screen)'
  1637.    do until pos(opts,'123456') \= 0
  1638.       say ''
  1639.       prompt = 'Select 1-6:'
  1640.       say prompt
  1641.          parse value SysCurPos() with row col
  1642.          row  = row - 1
  1643.          col = length(prompt) + 2
  1644.          call SysCurPos row, col
  1645.       opts = SysGetKey('NOECHO')
  1646.       say ''
  1647.    end
  1648.    select
  1649.       when opts = 1 then call max_news_packet
  1650.       when opts = 2 then call max_news_lines
  1651.       when opts = 3 then 
  1652.          do
  1653.             say ''
  1654.             say ''
  1655.             say ''
  1656.             call catch
  1657.             do_catchup_on_news = 1
  1658.             say 'All but' Howmany 'articles (each group) max. will be marked read.'
  1659.          end
  1660.       when opts = 4 then call read_only_getmail_mode
  1661.       when opts = 5 then
  1662.          do
  1663.             option1 = ''
  1664.             option2 = ''
  1665.             option3 = ''
  1666.             option4 = ''
  1667.             choice = 7    /* go back with same value for choice as we came with */
  1668.             say ''
  1669.             say 'Accepting defaults for all three options'
  1670.             say ''
  1671.             say ''
  1672.             say 'Press any key to continue'
  1673.             call SysGetKey 'NOECHO'
  1674.          end
  1675.       otherwise NOP
  1676.    end
  1677. end
  1678.  
  1679. getnews_xtra_options = option1 option2
  1680. getnews_xtra_options = strip(getnews_xtra_options, 'B')
  1681. getnews_xtra_options = getnews_xtra_options option3
  1682. getnews_xtra_options = strip(getnews_xtra_options, 'B')
  1683.  
  1684. getmail_xtra_options = option4
  1685. getmail_xtra_options = strip(getmail_xtra_options, 'B')
  1686.  
  1687. if do_catchup_on_news then
  1688.   do
  1689.       say ''
  1690.       say 'Communicating with news server' default_news
  1691.       say 'to update our NEWSRC...'
  1692.       souper_exe '-c' Howmany    /* mark as read all but last Howmany you set */
  1693.       say 'Each group in NEWSRC file caught up for all but last' Howmany 'articles.'
  1694.       say 'Articles not marked as read can be retrieved next.'
  1695.    end 
  1696. say ''
  1697. say 'Final Souper command-line option settings now are:'
  1698. say 'GETNEWS souper.exe options:' souper_getnews_std_options getnews_xtra_options
  1699. say 'GETMAIL souper.exe options:' souper_getmail_std_options getmail_xtra_options
  1700. say 'SENDING souper.exe options:' souper_send_std_options send_xtra_options
  1701.  
  1702. RETURN
  1703.  
  1704. max_news_packet:
  1705.      do until datatype(option1, 'W')
  1706.          call SysCls
  1707.          say ''
  1708.          say 'Enter a number in kilobytes for maximum news packet size.'
  1709.          say '2048 is typical. 0 sets packet size to unlimited.'
  1710.          say ''
  1711.          prompt = 'Enter number of kilobytes now:'
  1712.          say prompt
  1713.          parse value SysCurPos() with row col
  1714.          row  = row - 1
  1715.          col = length(prompt) + 2
  1716.          call SysCurPos row, col
  1717.          pull option1
  1718.          if \DataType(option1, 'W') then say 'Must be whole number or zero.'
  1719.      end
  1720.      say ''
  1721.      say 'Maximum packet size for news is set to' option1 'kilobytes'
  1722.      option1 = '-k' option1
  1723.      say ''
  1724.      say ''
  1725.      say 'Press any key to continue'
  1726.      call SysGetKey 'NOECHO'
  1727. RETURN
  1728.  
  1729. max_news_lines:
  1730.       call SysCls
  1731.       do until datatype(option2, 'W')
  1732.          say ''
  1733.          say 'Do not retrieve articles with more than this many lines'
  1734.          say 'in the body of the article.  Enter 0 for unlimited (the'
  1735.          say 'usual default for souper).'
  1736.          say ''
  1737.          prompt = 'Enter maximum lines:'
  1738.          say prompt
  1739.          parse value SysCurPos() with row col
  1740.          row  = row - 1
  1741.          col = length(prompt) + 2
  1742.          call SysCurPos row, col
  1743.          pull option2
  1744.          if \DataType(option2, 'W') then say 'Must be whole number or zero.'
  1745.      end
  1746.      say ''
  1747.      say 'Reject newsgroup articles with more than' option2 'lines in body.'
  1748.      if option2 = 0 then option2 = ''
  1749.         else option2 = '-l' option2
  1750.      say ''
  1751.      say ''
  1752.      say 'Press any key to continue'
  1753.      call SysGetKey 'NOECHO'
  1754. RETURN
  1755.  
  1756. read_only_getmail_mode:
  1757.       call SysCls
  1758.       do until pos(option4, 'YN') \=0
  1759.          say ''
  1760.          say 'For mail: You can set to read-only.  Retrieves mail but',
  1761.          say 'does not empty POP3 mailbox.'
  1762.          say ''
  1763.          say 'Set to Read-Only Mode?'
  1764.          prompt = 'Y sets Read-Only mode, N (normal default) doesn''t:'
  1765.          say prompt
  1766.             parse value SysCurPos() with row col
  1767.             row  = row - 1
  1768.             col = length(prompt) + 2
  1769.             call SysCurPos row, col
  1770.          parse upper pull option4
  1771.      end
  1772.      if option4 ='Y' then
  1773.          do
  1774.             say 'Read-Only mode set'
  1775.             option4 = '-r'
  1776.          end
  1777.      else
  1778.          do
  1779.             say 'Regular (not Read-Only) mode set'
  1780.             option4 = ''
  1781.          end 
  1782.      say ''
  1783.      say ''
  1784.      say 'Press any key to continue'
  1785.      call SysGetKey 'NOECHO'
  1786. RETURN
  1787.  
  1788.  
  1789. /*
  1790. ==============================================
  1791. are_there_interfaces_up()
  1792.  
  1793. Checks for active router interfaces.  We look specifically
  1794. for an interface with the same characters in interf_prefix
  1795. (or at least, for its forst n characters where n=length of
  1796. interface_prefix).  Returns ifprefix_interf_up=1 if found.
  1797.  
  1798. Then, whatever the prefix, checks whether any interface(s)
  1799. are up whether its prefix is interf_prefix, sl, ppp, slip,
  1800. lan, l, or whatever.  Returns some_interf_up=1 if found.
  1801. ==============================================
  1802. */
  1803.  
  1804. are_there_interfaces_up:
  1805. if_prefix = translate(interf_prefix)
  1806.  
  1807. some_interf_up = 0 
  1808. ifprefix_interf_up = 0
  1809. some_interf_up = 0
  1810.  
  1811. netstat_line = ''
  1812. 'netstat -r | rxqueue /LIFO'    /* send output to the queue */
  1813. do queued()
  1814.    parse pull netstat_line /* interface may be last word */
  1815.    dest = word(netstat_line, 1)
  1816.    dest = translate(dest)
  1817.    dest = strip(dest, 'B')
  1818.    if dest = 'DESTINATION' then iterate /* line is the heading line, discard */
  1819.    interface = word(netstat_line, words(netstat_line))
  1820.    interface = translate(interface)
  1821.    if left(interface, length(interf_prefix)) = if_prefix then
  1822.       ifprefix_interf_up = 1
  1823.    if interface \= '' then some_interf_up = 1      /* anything */
  1824. end
  1825. RETURN
  1826.  
  1827. /*
  1828. =====================
  1829. make_if_list()
  1830.  
  1831. Creates a string of all router interfaces detected,
  1832. with spaces as separators.  The interfaces are
  1833. translated to upper case before being recorded in the string.
  1834.  
  1835.  
  1836. possible examples of what an if _list will look like:
  1837. if_list = 'PPP3 PPP1 SL0'
  1838. if_list = ''    (none detected)
  1839. if_list = 'SL0'
  1840.  
  1841. if_list  includes all interface types; they can be mixed
  1842.  
  1843. make_if_list() returns the list (the string if_list)
  1844. =====================
  1845. */ 
  1846. make_if_list:
  1847.  
  1848. if_list = ''
  1849.  
  1850. 'netstat -r | rxqueue /LIFO'    /* send output to the queue */
  1851. do queued()
  1852.    parse pull netstat_line /* interface may be last word */
  1853.    interface = word(netstat_line, words(netstat_line))
  1854.    interface = translate(interface)
  1855.    dest = word(netstat_line, 1)
  1856.    dest = translate(dest)
  1857.    dest = strip(dest, 'B')
  1858.    if dest = 'DESTINATION' then iterate /* line is the heading line, discard */
  1859. /* if interface is not in the list, add it */
  1860.    if pos(interface, if_list) = 0 then if_list = if_list interface
  1861. end
  1862.  
  1863. RETURN if_list
  1864.  
  1865. /*
  1866. ==============================================
  1867. wait_for_interface()
  1868.  
  1869. Waits for a new interface to become active, which is
  1870. deduced from comparison of interface(s) returned by NETSTAT.EXE -r
  1871. to the string prepared before starting the dialer of all
  1872. (any) pre-existing interfaces (if_list).
  1873.  
  1874. Takes two arguments which are
  1875.    total_delay        the wait until timeout, seconds
  1876.    quiet        quiet mode if 1, verbose mode if 0
  1877.  
  1878. Returns the variable found_interface which =1 if 
  1879. a new interface is detected or =0 if we time out
  1880. before finding a new one.
  1881. ==============================================
  1882. */
  1883.  
  1884. wait_for_interface:
  1885. parse arg total_delay, quiet
  1886.  
  1887. recheck_delay = 1    /* recheck interval in seconds */
  1888. if_prefix = translate(interf_prefix)
  1889. ifp_length = length(interf_prefix)
  1890.  
  1891. say 'Waiting for' service '(' || interf_prefix || ') - maximum wait =' total_delay 'second(s)'
  1892.  
  1893. found_interface = 0        /* clear to not found */
  1894. do index = 1 to total_delay by recheck_delay      /* Periodically check avail. routes */
  1895.    call SysSleep recheck_delay    /* Minor delay, then check for routes */
  1896.    'netstat -r | rxqueue /LIFO'    /* send output to the queue */
  1897.  
  1898.    do queued()
  1899.       parse pull netstat_line    /* May have interface as last word in line */
  1900.       dest = word(netstat_line, 1)
  1901.       dest = translate(dest)
  1902.       dest = strip(dest, 'B')
  1903.       if dest = 'DESTINATION' then iterate /* line is the heading line, discard */
  1904.       interface = word(netstat_line, words(netstat_line))
  1905.       interface = translate(interface)
  1906.       if left(interface, ifp_length) = if_prefix then     /* Check for interface */
  1907.          do
  1908.             if pos(interface, if_list) = 0 then
  1909.                do
  1910.                   found_interface = 1 /* (new) , we did not time out */ 
  1911.                   if \quiet then say 'interface' interface 'detected'
  1912.                   leave index
  1913.                end
  1914.        end    /* of If Left(interface, ifp_length) = if_prefix */
  1915.     end            /* of Do Queued() */
  1916. end            /* of Do Index */ 
  1917. do queued(); pull; end    /* Clear out any lines left in rxqueue */ 
  1918. RETURN found_interface
  1919.  
  1920.  
  1921. /*
  1922. ==============================================
  1923. HANDLING OF ERROR TRAPS
  1924.  
  1925. ReXX Errors (failure, halt, syntax, novalue, error,
  1926. novalue) that occur with SIGNAL ON XXXXX (XXXXX = failure,
  1927. halt, etc.) are diverted (we jump) to one of these
  1928. where the error and the offending line are identified.
  1929. ==============================================
  1930. */
  1931.  
  1932.    FAILURE:
  1933.    say 'Rexx FAILURE condition' rc 'in line' sigl ':' errortext(rc)
  1934.    say sourceline(sigl)
  1935.  
  1936.    call beep 300, 500
  1937.    do_not_kill = 0
  1938.    signal goodbye
  1939.    RETURN
  1940.  
  1941.  
  1942.    HALT:
  1943.    say 'Rexx HALT condition' rc 'in line' sigl ':' errortext(rc)
  1944.    say sourceline(sigl)
  1945.  
  1946.    call beep 300, 500
  1947.    do_not_kill = 0
  1948.    signal goodbye
  1949.    RETURN
  1950.  
  1951.  
  1952.    SYNTAX:
  1953.    say 'Rexx SYNTAX error' rc 'in line' sigl ':' errortext(rc)
  1954.    say sourceline(sigl)
  1955.  
  1956.    call beep 300, 500
  1957.    do_not_kill = 0
  1958.    signal goodbye
  1959.    RETURN
  1960.  
  1961.  
  1962.    NOTREADY:
  1963.    say 'Rexx NOTREADY condition' rc 'in line' sigl ':' errortext(rc)
  1964.    say sourceline(sigl)
  1965.  
  1966.    call beep 300, 500
  1967.    do_not_kill = 0
  1968.    signal goodbye
  1969.    RETURN
  1970.  
  1971.  
  1972.    ERROR:
  1973.    say 'Rexx ERROR condition' rc 'in line' sigl ':' errortext(rc)
  1974.    say sourceline(sigl)
  1975.  
  1976.    call beep 300, 500
  1977.    do_not_kill = 0
  1978.    signal goodbye
  1979.    RETURN
  1980.  
  1981.  
  1982.    NOVALUE:
  1983.    say 'Rexx NOVALUE condition' rc 'in line' sigl ':' errortext(rc)
  1984.    say sourceline(sigl)
  1985.  
  1986.    call beep 300, 500
  1987.    do_not_kill = 0
  1988.    signal goodbye
  1989.    RETURN
  1990.  
  1991. /*
  1992. =======================
  1993. goodbye()
  1994. quit()
  1995. depart()
  1996.  
  1997. Exit routines.  Most exits are jumps to
  1998. goodbye()
  1999. =======================
  2000. */
  2001.  
  2002. goodbye:
  2003. call kill_dialers_slip_ppp_slattach    /* Now fall into DEPART() */
  2004.  
  2005. Depart:
  2006. if timeout then signal Quit
  2007. say ''
  2008. call connect_stats        /* tell us elapsed time */
  2009. x= EndLocal()
  2010.  
  2011.     /* Now fall into QUIT() */
  2012. Quit:                /* Fall into Quit */
  2013. say ''
  2014. say 'Done. Press any key to exit...'        
  2015. answer = SysGetKey('NOECHO')
  2016.  
  2017. EXIT
  2018.  
  2019. RETURN